#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
@File Name: 一个堆栈模块_stack1.py
@Author: LT
@Date: 2021/9/26 18:28
# -----------------------------------------------------------------------------------------------------
@Description: 
一个共享栈模块
# -----------------------------------------------------------------------------------------------------
"""
stack = []


class error(Exception):
    pass


def push(obj):
    global stack
    stack = [obj] + stack


def pop():
    global stack
    if not stack:
        raise error("stack underflow")          # 也可以抛出IndexError
    top, *stack = stack
    return top


def empty(): return not stack                   # 判断是否为空
def hasmember(obj): return obj in stack         # 判断元素是否存在
def item(offset): return stack[offset]          # 根据未知返回栈中元素
def length(): return len(stack)                 # 返回栈的长度
def dump(): print("<Stack:%s>" % stack)


if __name__ == '__main__':
    pass
